

#include <config.h>

#ifndef _SUDOKU_H
#  define _SUDOKU_H

#  include <sdk_llist.h>

/* Sudoku data structure is defined here. */

typedef struct _sdk_square {

  char val;
  char row;
  char col;
  sdk_llist_t *pos;

} sdk_square;

typedef struct _sudoku {

  sdk_square sdk_data[SDK_WIDTH][SDK_WIDTH];
  char solved;

} sudoku;

/* Defines for the sudoku data structures. */

#  define SDK_ALLOC_SQUARE() (sdk_square *)sdk_malloc_sqr()
#  define SDK_ALLOC_SUDOKU() (sudoku *)sdk_malloc_sdk()
#  define SDK_FREE_SQUARE(SQR) sdk_free(SQR, sizeof(sdk_square))
#  define SDK_FREE_SUDOKU(SDK) sdk_free_sudoku(SDK)

#  define SDK_SET_SQUARE(SDK, ROW, COL, VAL) (SDK->sdk_data[ROW][COL].val = VAL)
#  define SDK_GET_SQUARE(SDK, ROW, COL) (SDK->sdk_data[ROW][COL])
#  define SDK_GET_SQUARE_VAL(SDK, ROW, COL) (SDK_GET_SQUARE(SDK, ROW, COL).val)

#  define SDK_COL 0
#  define SDK_ROW 1

/* Sudoku functions. */

sudoku      *sdk_load_sudoku(char *);
sudoku      *sdk_copy_sudoku(sudoku *);
sudoku      *sdk_solve(sudoku *);
int          sdk_solved(sudoku *);
int          sdk_solvable(sudoku *);
void         sdk_print_sudoku(sudoku *);
void         sdk_print_sudoku_square(sdk_square *);
void         sdk_generate_lists(sudoku *);
int          sdk_set_square_vals(sudoku *);
void         sdk_flesh_sudoku(sudoku *);
sudoku      *sdk_malloc_sdk();
sdk_square  *sdk_malloc_sqr();
void         sdk_free_sudoku(sudoku *);

/* Underscored solving functions. */

sdk_square *_sdk_find_branch_square(sudoku *);


/* Real solving functions */

sudoku     *_sdk_solve(sudoku *);
sudoku     *_sdk_rec_solve(sudoku *);

/* Info printing functions. */

void         sdk_msg(char *, char *);

#endif
